const users = {
  codercqw: {
    name: 'codercqw',
    password: '123456',
    avatar:
      'https://avatars.githubusercontent.com/u/42881193?s=460&u=aa1571bcaa65664f794bd24173dbc54737e9920b&v=4',
    token: 'codercqw-token'
  }
}
module.exports = [
  {
    url: '/user/login',
    type: 'post',
    response: res => {
      const { name, password } = res.body
      const userInfo = users[name]
      if (userInfo && password == userInfo.password) {
        return {
          code: 200,
          data: {
            userInfo
          }
        }
      } else {
        return {
          code: 30000,
          data: {
            message: '账号或密码错误'
          }
        }
      }
    }
  },
  {
    url: '/user/logout',
    type: 'put',
    response: res => {
      return {
        code: 200,
        data: {
          message: '退出登录'
        }
      }
    }
  },
  {
    url: '/user/getUserInfo',
    type: 'get',
    response: res => {
      let { token } = res.headers
      const userInfo = Object.keys(users).find(user => (user.token = token))
      if (!userInfo) {
        return {
          code: 39999,
          message: 'token已过期，请重新登录'
        }
      }
      return {
        code: 200,
        data: {
          userInfo: users[userInfo]
        }
      }
    }
  }
]
